// evaluate.js
var app = getApp()
import { formatRaty, formatComment } from "../../utils/util.js";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    evaluateList: [],
    user: {},
    length: null,
    monyStars: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let user = wx.getStorageSync('wechat_user')
    user.raty_parse = formatRaty(user.raty)
    this.setData({ user: user })
    this.evaluateList()
  },
  //获取评价列表
  evaluateList: function () {
    let self = this
    app.query("web/users/" + self.data.user.id + "/comments", { page: 1 }).then((res) => {
      console.log(res)
      let evaluate = formatComment(res.comments)
      self.setData({
        evaluateList: evaluate,
        length: evaluate.length
      })
      self.stars()
    })
  },
  //星星判断
  stars: function () {
    let self=this
    var starsList = []
    let imgObj
    for (var i in self.data.evaluateList) {
      let imgObj={}
      imgObj.url="../img/me/order_star.png"
      console.log(self.data.evaluateList[i].raty)
      if (self.data.evaluateList[i].raty != null) {
        switch (self.data.evaluateList[i].raty) {
          case 1: starsList[i].concat(imgObj); break;
          case 2: starsList[i].concat(imgObj, imgObj); break;
          case 3: starsList[i].concat(imgObj, imgObj, imgObj); break;
          case 4: starsList[i].concat(imgObj, imgObj, imgObj, imgObj); break;
          case 5: starsList[i].concat(imgObj, imgObj, imgObj, imgObj, imgObj); break;
        }
      }
    }
    console.log(starsList)
    this.setData({
      monyStars: starsList
    })
   
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})